package cn.com.visionsky.bocsz.bda.webservice.util;

import org.apache.commons.lang.StringUtils;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by 46043 on 2016/11/11.
 */
public class DateXmlAdapter extends XmlAdapter<String, Date> {
    private SimpleDateFormat yyyyMMddHHmm = new SimpleDateFormat(
            "yyyyMMdd");

    @Override
    public Date unmarshal(String string) throws Exception {
        if (StringUtils.isBlank(string)) {
            return null;
        }
        return yyyyMMddHHmm.parse(string);
    }

    @Override
    public String marshal(Date date) throws Exception {
        return yyyyMMddHHmm.format(date);
    }
}
